package com.audaque.springboot.foshanupload.session.filter;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@Slf4j
public class SessionLogoutFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
        log.debug("init SessionLogoutFilter ");
    }


    @Override
    public void doFilter(final ServletRequest req,
                         final ServletResponse res,
                         final FilterChain chain) throws IOException, ServletException {
        final HttpServletRequest request = (HttpServletRequest) req;
        final HttpServletResponse response = (HttpServletResponse) res;
        String url = request.getRequestURL().toString();
        log.debug("url：" + url);

        HttpSession session = request.getSession();
        //注销session
        session.invalidate();


        chain.doFilter(req, res);
        return;
    }

}
